/* 表单提交数据
 * H5FormData.js
 */

 import { combineReducers } from 'redux';

 function loadingData(state=false,action){
	switch (action.type) {
		case 'H5_LIST_FORM_DATA':
			return false;
		case 'H5_LIST_FORM_MORE_DATA':
			return false;
		case 'H5_LIST_FORM_DATA_START':
			return true;
		case 'H5_LIST_FORM_DATA_END':
			return false;	
	   	default:
		   	return state;
  	}
}

function datalist(state=Array(),action){
	switch (action.type) {
		case 'H5_LIST_FORM_DATA':
			let list=Array();
			action.datalist.map(item=>{
				let data=item.submit_data;
				list.push({...data,'提交页面':item.submit_page_num,'提交时间':item.submit_time,id:item.id});
			});
			return list;
		case 'H5_LIST_FORM_MORE_DATA':
			let totalList=state;
			action.datalist.map(item=>{
				let data=item.submit_data;
				totalList.push({...data,'提交页面':item.submit_page_num,'提交时间':item.submit_time,id:item.id});
			});
			return totalList;
		case 'CLEAR_H5_FORM_LIST_DATA':
			return new Array();
	   	default:
		   	return state;
  	}
}

function submitPageNums(state=Array(),action){
	switch (action.type) {
		case 'H5_LIST_FORM_DATA':
			let list=Array();
			action.submitPageNums.map(item=>{
				list.push(item.submit_page_num);
			});
			return list;
		case 'CLEAR_H5_FORM_LIST_DATA':
			return new Array();
	   	default:
		   	return state;
  	}
}

export default combineReducers({datalist,loadingData,submitPageNums});
